package singleton;

/**
 * @program: javase
 * @description: 饿汉式
 * 缺点：通过类加载时就初始化了对象，如果还没没有使用，会造成资源的浪费
 * @author: luolidong
 * @create: 2021-06-12 15:16
 * @version: 1.0
 */
public class Singleton1 {
    private Singleton1() {
    }

    //静态常量
    public static Singleton1 singleton1 = new Singleton1();

    public static Singleton1 getInstance() {
        return singleton1;
    }

    //    测试
    public static void main(String[] args) {
        Singleton1 instance = getInstance();
        Singleton1 instance1 = getInstance();
        System.out.println(instance == instance1);
    }
}
